package com.longcai.cm.base;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author MACHENIKE
 */
@Data
@ApiModel(description = "分页信息")
public class Page<T> {

    @ApiModelProperty(value = "单页数据量", example = "10")
    private Integer rows;

    @ApiModelProperty(value = "页码", example = "1")
    private Integer currentPage;

    @ApiModelProperty(required = true, notes = "总数据量", example = "213")
    private Long total;

    @ApiModelProperty(required = true, notes = "最大页数", example = "111")
    private Long maxPage;

    @ApiModelProperty(required = true, notes = "数据信息", dataType = "T")
    private T content;

    public String convertPage() {
        int limit = (currentPage - 1) * rows;
        return " limit " + limit + ", " + rows;
    }

    public String convertPage(Integer currentPage, Integer rows) {
        int limit = (currentPage - 1) * rows;
        return " limit " + limit + ", " + rows;
    }

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }

    public Page(Integer currentPage, Integer rows, Long total) {
        this.rows = rows;
        this.currentPage = currentPage;
        this.total = total;
        this.maxPage = total % rows == 0 ? total / rows : total / rows + 1;
    }


}
